# -*- coding: utf-8 -*-
"""
execute a shell script in a single node
"""

from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division

from subprocess import call
from kgpipeline.job import KgJob, JobConfigError


class KgShellJob(KgJob):
    type_key = "shell"

    def process(self, inputs):
        command = self.config.get("command")
        if not command:
            raise JobConfigError("Input parameter `command` is missing!")

        if not isinstance(command, list):
            raise JobConfigError("Input parameter `command` should be a list!")

        call(command)


KgJob.register("shell", KgShellJob)
